package com.fanbai.score.business.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.fanbai.score.R;
import com.fanbai.score.business.fragemnt.Home_Fragment;
import com.fanbai.score.business.fragemnt.BusinessManage_Fragment;
import com.fanbai.score.common.fragment.WebViewFragment;
import com.fanbai.score.common.base.BaseActivity;


public class BusinessMainActivity extends BaseActivity implements TabLayout.OnTabSelectedListener{

    private SectionsPagerAdapter mSectionsPagerAdapter;

    private ViewPager mViewPager;

    /**
     * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
     * one of the sections/tabs/pages.
     */
    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a Home_Fragment (defined as a static inner class below).
            switch (position) {
                case 0:
                    return Home_Fragment.newInstance(position + 1);
                case 1:
                    return WebViewFragment.newInstance("http://score.xinyou777.cn/shopadmin/html/guirenqianbao.html", "贵人钱包");
                case 2:
                    return BusinessManage_Fragment.newInstance(position + 1);
            }
            return Home_Fragment.newInstance(position + 1);
        }

        @Override
        public int getCount() {
            // Show 3 total pages.
            return 3;
        }

    }

    TabLayout tabLayout;

    @Override
    protected int getLayoutID() {
        return R.layout.user_activity_main;
    }

    @Override
    public String getTitleName() {
        return null;
    }

    @Override
    protected void initView() {
        toolbar.setVisibility(View.GONE);
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        mViewPager = (ViewPager) findViewById(R.id.container);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.addTab(tabLayout.newTab().setText("老板").setIcon(R.mipmap.icon_user_home_h));
        tabLayout.addTab(tabLayout.newTab().setText("贵人钱包").setIcon(R.mipmap.icon_user_qianbao_h));
        tabLayout.addTab(tabLayout.newTab().setText("老板管理").setIcon(R.mipmap.icon_user_huodong_h));
        mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        tabLayout.setOnTabSelectedListener(this);

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {
        mViewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {
    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }
}
